package com.ydj.app.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.ydj.framework.exception.CommonException;
import com.ydj.framework.protocol.JsonResult;
import com.ydj.app.entity.CmsAccount;
import com.ydj.app.protocol.http.oldcms.*;
import com.ydj.app.service.CmsAccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

@RestController
@RequestMapping("/cms/account")
@Api(tags = "CMS-内部账号")
public class CmsAccountController {

    @Autowired
    private CmsAccountService cmsAccountService;

    @ResponseBody
    @ApiOperation(value = "获取账号列表")
    @ApiOperationSupport(order = 10)
    @PostMapping(value = "/getAccountList")
    public JsonResult<CmsAccountGetAccountListRes> getAccountList(@RequestBody @Validated CmsAccountGetAccountListReq req, @ApiIgnore CmsAccount account) throws CommonException {
        CmsAccountGetAccountListRes res = cmsAccountService.cmsGetAccountList(req, account);
        return JsonResult.success(res);
    }

    @ResponseBody
    @ApiOperation(value = "创建账号")
    @ApiOperationSupport(order = 11)
    @PostMapping(value = "/createAccount")
    public JsonResult<CmsAccountCreateAccountRes> createAccount(@RequestBody @Validated CmsAccountCreateAccountReq req, @ApiIgnore CmsAccount account) throws CommonException {
        CmsAccountCreateAccountRes res = cmsAccountService.cmsCreateAccount(req, account);
        return JsonResult.success(res);
    }

    @ResponseBody
    @ApiOperation(value = "修改账号")
    @ApiOperationSupport(order = 12)
    @PostMapping(value = "/updateAccount")
    public JsonResult<?> updateAccount(@RequestBody @Validated CmsAccountUpdateAccountReq req, @ApiIgnore CmsAccount account) throws CommonException {
        cmsAccountService.cmsUpdateAccount(req, account);
        return JsonResult.success();
    }

    @ResponseBody
    @ApiOperation(value = "修改密码")
    @ApiOperationSupport(order = 13)
    @PostMapping(value = "/updatePassword")
    public JsonResult<?> updatePassword(@RequestBody @Validated CmsAccountUpdatePasswordReq req, @ApiIgnore CmsAccount account) throws CommonException {
        cmsAccountService.cmsUpdatePassword(req, account);
        return JsonResult.success();
    }

    @ResponseBody
    @ApiOperation(value = "修改是否启用")
    @ApiOperationSupport(order = 14)
    @PostMapping(value = "/updateEnable")
    public JsonResult<?> updateEnable(@RequestBody @Validated CmsAccountUpdateEnableReq req, @ApiIgnore CmsAccount account) throws CommonException {
        cmsAccountService.cmsUpdateEnable(req, account);
        return JsonResult.success();
    }
}